﻿using Microsoft.Extensions.DependencyInjection;
namespace AutoClickTool.Common.ExceptionExten
{
    public static class ExceptionHandlerExtensions
    {
        public static void AddExceptionHandler(this ServiceProvider services)
        {
            // 捕获未处理的线程异常
            Application.ThreadException += (sender, args) =>
            {
                services.GetRequiredService<IExceptionHandler>().HandleException(args.Exception);
            };
            // 捕获未处理的应用程序域异常
            AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
            {
                Exception ex = (Exception)args.ExceptionObject;
                services.GetRequiredService<IExceptionHandler>().HandleException(ex);
            };
        }
    }
}
